﻿#nullable enable

namespace NServiceBus;

using System;

/// <summary>
/// Provides the ability to specify TTBR using a convention.
/// </summary>
public static class TimeToBeReceivedConventionExtensions
{
    extension(ConventionsBuilder builder)
    {
        /// <summary>
        /// Sets the function to be used to evaluate whether a message has a time to be received.
        /// </summary>
        public ConventionsBuilder DefiningTimeToBeReceivedAs(Func<Type, TimeSpan> retrieveTimeToBeReceived)
        {
            ArgumentNullException.ThrowIfNull(builder);
            ArgumentNullException.ThrowIfNull(retrieveTimeToBeReceived);

            builder.Settings.Set(new UserDefinedTimeToBeReceivedConvention(retrieveTimeToBeReceived));

            return builder;
        }
    }
}